package vincent.com.layouttest;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>{
    private Context mContext;
    private List<String> data;

    public MyAdapter(Context context, List<String> data){
        this.mContext = context;
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(mContext).inflate(android.R.layout.simple_list_item_1, parent, false);
        return new MyViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String str = data.get(position);
        holder.txt.setText("Item" + position);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView txt;
        public MyViewHolder(View itemView) {
            super(itemView);
            txt = (TextView)itemView.findViewById(android.R.id.text1);
        }
    }
}